package com.boot.utils;

import org.jasig.cas.client.authentication.AttributePrincipal;
import org.jasig.cas.client.util.AbstractCasFilter;
import org.jasig.cas.client.validation.Assertion;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Chunsheng.Zhang
 * @date 2021/1/12 16:38
 * @description : TODO
 */
public class CASUtil {



    /**
     * @description: 获取当前登录用户名
     * @author: ChunSheng.Zhang
     * @date: 2021/1/12 16:38
     * @param request
     * @return java.lang.String
     **/
    public static String getAccountNameFromCas(HttpServletRequest request) {

        Assertion assertion = (Assertion) request.getSession().getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
        if(assertion!= null){
            AttributePrincipal principal = assertion.getPrincipal();
            return principal.getName();
        }else {return null;}

    }

}
